package com.zhang.aloneway_springboot.service.impl;


import com.zhang.aloneway_springboot.dao.UserDao;
import com.zhang.aloneway_springboot.pojo.User;
import com.zhang.aloneway_springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public boolean isExist(String username) {
        //这个方法要调用下面那个getByName方法

        return false;
    }

    @Override
    public User getByName(String username) {
        //通过userDao对象去调用它自己身上的findByUsername方法（在UserDao中定义的），来获得User对象
        User user = userDao.findByUsername(username);
        return user;
    }

    @Override
    public User getUser(String username, String password) {
        User user = userDao.getByUsernameAndPassword(username, password);
        return user;
    }

    @Override
    public void addUser(User user) {
        userDao.save(user);
        //这个save方法是由于用了JPA
        //所以可以自由使用org.springframework.data.repository.CrudRepository<T, ID>中提供的这个方法
    }
}
